'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/user/login', sign(), controller.user.login);
  } else {
    router.post('/api/user/login', controller.user.login);
  }
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/member', controller.user);
  // category
  router.get('/api/category/list', controller.category.allList);
  router.resources('category', '/api/category', controller.category);
  // area
    router.get('/api/area/list', controller.area.allList);
    router.resources('area', '/api/area', controller.area);
  router.get('/api/server/list', controller.server.allList);
  router.resources('server', '/api/server', controller.server);
  // tag
    router.get('/api/tag/list', controller.tag.allList);
    router.resources('tag', '/api/tag', controller.tag);
  // condition
    router.get('/api/condition/list', controller.condition.allList);
    router.resources('condition', '/api/condition', controller.condition);
  // goods
    router.get('/api/goods/list', controller.goods.allList);
    router.resources('goods', '/api/goods', controller.goods);
    // conditionValue
    router.get('/api/conditionValue/list', controller.conditionValue.allList);
    router.resources('conditionValue', '/api/conditionValue', controller.conditionValue);
};
